package com.hospes.rmes;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.hospes.rmes.constants.ConstMain;
import com.hospes.rmes.core.ImageDescriptor;
import com.hospes.rmes.models.News;
import com.hospes.rmes.utils.Utils;

/**
 * Created by IntelliJ IDEA.
 * User: Andrew Khloponin
 * Date: 21.06.11
 */
public class NewsViewActivity extends Activity {

	private News news = new News();
	private TextView tvTitle, tvText, tvTeaser;
	private ImageView ivPoster;
	private ProgressBar pbPoster;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.i(ConstMain.LOG_TAG, "Start " + this.getClass().getName());
		setContentView(R.layout.view_newsview);

		/** getting data from previous activity */
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			news = extras.getParcelable("news");
		}

		tvTitle = (TextView) findViewById(R.id.tv_newsview_title);
//		tvText = (TextView) findViewById(R.id.tv_newsview_text);
		tvTeaser = (TextView) findViewById(R.id.tv_newsview_teaser);
		ivPoster = (ImageView) findViewById(R.id.iv_newsview_poster);
		pbPoster = (ProgressBar) findViewById(R.id.pb_newsview_poster);

		tvTitle.setText(news.title);
//		tvText.setText(Html.fromHtml(news.text));
//		tvText.setMovementMethod(LinkMovementMethod.getInstance());
//		tvText.setTextColor(Color.GRAY);
		tvTeaser.setText(Html.fromHtml(news.teaser));
		tvTeaser.setMovementMethod(LinkMovementMethod.getInstance());
		tvTeaser.setTextColor(Color.GRAY);

		ImageDescriptor image = new ImageDescriptor(Utils.getFileName("http://rmes.com.ua/files/images/" + news.files), "http://rmes.com.ua/files/images/" + news.files);
		App.imageDownloader.download(image, ivPoster, pbPoster);
	}
}
